import 'package:flutter/material.dart';
import 'package:flutter_study/datas/goodsData.dart';

void main() => runApp(InfoListApp());

class InfoListApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('信息列表'),
        ),
        body: InfoListAppWidget(),
      ),
      theme: ThemeData(accentColor: Colors.pink),
    );
  }
}

class InfoListAppWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ListView(
      children: goodsData.map((value) {
        return Card(
          margin: EdgeInsets.all(12),
          child: Column(
            children: [
              // 顶部图片
              AspectRatio(
                aspectRatio: 16 / 9,
                child: Image.network(
                  value['imageUrl'],
                  fit: BoxFit.cover,
                ),
              ),
              // 描述
              ListTile(
                leading: CircleAvatar(
                  backgroundImage: NetworkImage(value['imageUrl']),
                ),
                title: Text(value['title']),
                subtitle: Text(
                  value['description'],
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ),
              )
            ],
          ),
        );
      }).toList(),
    );
  }
}
